package com.hua.proxystatic;
//静态代理模式，真实对象和代理对象都要实现同一个接口

/*
代理对象可以做很多真实对象做不了的事情，真实对象专注自己的事情就是了



 */
public class StaticProxy {
    public static void main(String[] args) {
        You you = new You();
        new Thread(()-> System.out.println("我爱你")).start();
        new WeddingCompany(new You()).HappyMarry();
//        WeddingCompany weddingCompany = new WeddingCompany(you);
//        weddingCompany.HappyMarry();
    }


}
interface Marry{
    void HappyMarry();

}
class You implements Marry{//你是真实角色


    @Override
    public void HappyMarry() {
        System.out.println("我要结婚了，好快乐");
    }
}
class WeddingCompany implements Marry{ //婚庆公司它是代理角色，帮助你结婚
    //代理对象要代理真实角色
    private Marry target;

    public WeddingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void HappyMarry() {
        before();
        this.target.HappyMarry();
        after();
    }

    private void after() {
        System.out.println("结婚之后收尾款！");
    }

    private void before() {
        System.out.println("结婚之前布置现场");
    }
}